package com.cgt.spring.test;

import com.cgt.spring.controller.CourseController;
import com.cgt.spring.controller.StudentController;
import com.cgt.spring.pojo.Student;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringDemo {
	@Test
	public void test1() {
		//创建Spring容器
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		//从Spring容器中根据名字取出new出来的对象
		Student student = (Student) context.getBean("student");
		System.out.println(student);
	}
	//单例多例测试
	@Test
	public void test2() {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		Student student1 = (Student) context.getBean("student");
		Student student2 = (Student) context.getBean("student");
		System.out.println(student1 == student2);// true
	}

	@Test
	public void test3() {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		StudentController studentController = (StudentController) context.getBean("studentController");
		studentController.selectAll();
	}

	@Test
	public void test4() {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		CourseController courseController = (CourseController) context.getBean("courseController");
		courseController.selectAll();
	}
}
